/**
 * CS340 Fatboy Mafia Team
 */
package fatboy.communication;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


//import java.net.UnknownHostException;

/**
 *	@author Ilya Vinogradov
 *	@ 23-Jan-10 11:17 PM
 *
 *	Client class is a communication demo driver. It connects to a server
 *	 and asks for user input. Whatever the user enters gets packaged into
 *	 the command object by proxy and sent over the network to the server.
 *
 *	 Proxy class takes care of sending the commands and receiving the
 *	 response from the server. 
 */
public class Client {
	private static final String ServerHost = "PROMETERY";
	//private static final String ServerHost = "gizbit";

	/**
	 * @param args
	 * @throws NoSuchMethodException 
	 * @throws SecurityException 
	 */
	public static void main(String[] args)
	throws IOException{
		
		//Preseting a database with local object
		ObjectID globalObjID = new ObjectID("PROMETERY",1L,new PortNumber());
		System.out.println("Global object id: " + globalObjID);
		BasicLocal originalObject = new BasicLocal("Initial Message",globalObjID);
		ResidentDatabase.initialize();
		ResidentDatabase.setObject(globalObjID, originalObject);
		//end presetting
		
        BasicProxy testProxy = new BasicProxy(
        		new ObjectID(ServerHost, 1L, PortNumber.getRuntimePort()));

	    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    String userInput = "";
	     
        System.out.print("Enter setVar String: ");
        userInput = in.readLine();
        while(!userInput.equalsIgnoreCase("quit"))
        {        
		    testProxy.setVar(userInput);
			testProxy.getVar();
			
	        System.out.print("Enter setVar String: ");
	        userInput = in.readLine();
        }
        
        // here we need to send something to the server if we want to shutdown it        
        // we could use another keyword (not "quit") to remotely shutdown server
	}
}
